package cz.najman.emdroid.listener;

import com.markupartist.android.widget.ActionBar;

public class ActionBarOnDataUpdatedListener extends DefaultOnDataUpdatedListener {

	private ActionBar mActionBar;
	private int pendingRequests = 0;
	
	public ActionBarOnDataUpdatedListener(ActionBar actionBar) {
		this.mActionBar = actionBar;
	}
	
	@Override
	protected void onRunning(Class objectClass) {
		pendingRequests++;
		mActionBar.setProgressBarVisibility(ActionBar.VISIBLE);
		super.onRunning(objectClass);
	}
	
	@Override
	protected void onFinished(Class objectClass) {
		
		if(--pendingRequests == 0){
			mActionBar.setProgressBarVisibility(ActionBar.INVISIBLE);
		}		
		super.onFinished(objectClass);
	}
	
	@Override
	protected void onError(Class objectClass) {
		if(--pendingRequests == 0){
			mActionBar.setProgressBarVisibility(ActionBar.INVISIBLE);
		}
		super.onError(objectClass);
	}	
	
}
